<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_configuration_envoi=new configuration_envoi();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["id"])){$_configuration_envoi->set_id($_POST["id"]);}
		if(isset($_POST["id_mail"])){$_configuration_envoi->set_id_mail($_POST["id_mail"]);}
		if(isset($_POST["date_envoi"])){$_configuration_envoi->set_date_envoi($_POST["date_envoi"]);}
		if(isset($_POST["heur_envoi"])){$_configuration_envoi->set_heur_envoi($_POST["heur_envoi"]);}
		if(isset($_POST["date_limite"])){$_configuration_envoi->set_date_limite($_POST["date_limite"]);}
		if(isset($_POST["heur_limte"])){$_configuration_envoi->set_heur_limte($_POST["heur_limte"]);}
		if(isset($_POST["parametre"])){$_configuration_envoi->set_parametre($_POST["parametre"]);}
		if(isset($_POST["etat_envoi"])){$_configuration_envoi->set_etat_envoi($_POST["etat_envoi"]);}
		$res=$_configuration_envoi->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["id"])){
		$_configuration_envoi->set_id($_POST["id"]);
		$res=$_configuration_envoi->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["id"])){$_configuration_envoi->set_id($_POST["id"]);}
		if(isset($_POST["id_mail"])){$_configuration_envoi->set_id_mail($_POST["id_mail"]);}
		if(isset($_POST["date_envoi"])){$_configuration_envoi->set_date_envoi($_POST["date_envoi"]);}
		if(isset($_POST["heur_envoi"])){$_configuration_envoi->set_heur_envoi($_POST["heur_envoi"]);}
		if(isset($_POST["date_limite"])){$_configuration_envoi->set_date_limite($_POST["date_limite"]);}
		if(isset($_POST["heur_limte"])){$_configuration_envoi->set_heur_limte($_POST["heur_limte"]);}
		if(isset($_POST["parametre"])){$_configuration_envoi->set_parametre($_POST["parametre"]);}
		if(isset($_POST["etat_envoi"])){$_configuration_envoi->set_etat_envoi($_POST["etat_envoi"]);}
		$res=$_configuration_envoi->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["id"]) && !empty($_POST["id"])){
		$constraint.=" AND id='".$_POST["id"]."'";
	}

	if(isset($_POST["id_mail"]) && !empty($_POST["id_mail"])){
		$constraint.=" AND id_mail='".$_POST["id_mail"]."'";
	}

	if(isset($_POST["date_envoi"]) && !empty($_POST["date_envoi"])){
		$constraint.=" AND date_envoi='".$_POST["date_envoi"]."'";
	}

	if(isset($_POST["heur_envoi"]) && !empty($_POST["heur_envoi"])){
		$constraint.=" AND heur_envoi='".$_POST["heur_envoi"]."'";
	}

	if(isset($_POST["date_limite"]) && !empty($_POST["date_limite"])){
		$constraint.=" AND date_limite='".$_POST["date_limite"]."'";
	}

	if(isset($_POST["heur_limte"]) && !empty($_POST["heur_limte"])){
		$constraint.=" AND heur_limte='".$_POST["heur_limte"]."'";
	}

	if(isset($_POST["parametre"]) && !empty($_POST["parametre"])){
		$constraint.=" AND parametre='".$_POST["parametre"]."'";
	}

	if(isset($_POST["etat_envoi"]) && !empty($_POST["etat_envoi"])){
		$constraint.=" AND etat_envoi='".$_POST["etat_envoi"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_configuration_envoi->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_configuration_envoi->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>